#include "NTest.h"
#include <stdio.h>
#include <stdarg.h>
#include <Windows.h>

#define STR_BUFFER_LEN 1024

void NLogf( const char * InMsg, ... )
{
	va_list Valist;
	char Buffer[STR_BUFFER_LEN];

	va_start(Valist, InMsg);
	vsprintf_s(Buffer, InMsg, Valist);
	va_end(Valist);

#if defined(UNICODE) || defined(_UNICODE)
	wchar_t Wbuffer[STR_BUFFER_LEN];
	int Ret = ::MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, Buffer, STR_BUFFER_LEN, Wbuffer, STR_BUFFER_LEN);
	if (!Ret)
	{
		return ;
	}

	wsprintf(TEXT("%s\n"), Wbuffer);	
#else

	printf(TEXT("%s\n"),Buffer);
#endif
}

void NLogf( const wchar_t * InMsg, ... )
{
	va_list Valist;
	wchar_t Wbuffer[STR_BUFFER_LEN];

	va_start(Valist, InMsg);
	vswprintf_s(Wbuffer, InMsg, Valist);
	va_end(Valist);

#if defined(UNICODE) || defined(_UNICODE)

	wsprintf(TEXT("%s\n"), Wbuffer);	
#else
	char Buffer[STR_BUFFER_LEN];
	int Ret = ::WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS , Wbuffer, STR_BUFFER_LEN, Buffer, STR_BUFFER_LEN, NULL, NULL);
	if (!Ret)
	{
		return ;
	}

	printf(TEXT("%s\n"), Buffer);
#endif
}

void NPause( const char * InMsg, ... )
{
	va_list Valist;
	char Buffer[STR_BUFFER_LEN];

	va_start(Valist, InMsg);
	vsprintf_s(Buffer, InMsg, Valist);
	va_end(Valist);

#if defined(UNICODE) || defined(_UNICODE)
	wchar_t Wbuffer[STR_BUFFER_LEN];
	int Ret = ::MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, Buffer, STR_BUFFER_LEN, Wbuffer, STR_BUFFER_LEN);
	if (!Ret)
	{
		return ;
	}

	wsprintf(TEXT("%s\n"), Wbuffer);	
#else

	printf(TEXT("%s\n"),Buffer);
#endif

	NPause();
}

void NPause( const wchar_t * InMsg, ... )
{
	va_list Valist;
	wchar_t Wbuffer[STR_BUFFER_LEN];

	va_start(Valist, InMsg);
	vswprintf_s(Wbuffer, InMsg, Valist);
	va_end(Valist);

#if defined(UNICODE) || defined(_UNICODE)

	wsprintf(TEXT("%s\n"), Wbuffer);	
#else
	char Buffer[STR_BUFFER_LEN];
	int Ret = ::WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS , Wbuffer, STR_BUFFER_LEN, Buffer, STR_BUFFER_LEN, NULL, NULL);
	if (!Ret)
	{
		return ;
	}

	printf(TEXT("%s\n"), Buffer);
#endif

	NPause();
}